package cn.tedu.charging.cost.controller;

import cn.tedu.charging.common.pojo.param.ProgressCostParam;
import cn.tedu.charging.common.pojo.vo.ProgressCostVO;
import cn.tedu.charging.common.protocol.JsonResult;
import cn.tedu.charging.cost.service.CostService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class CostController {
    @Autowired
    private CostService costService;

    @PostMapping("/cost/bill/calculate")
    public JsonResult<ProgressCostVO> calculateCost(@RequestBody ProgressCostParam cost){
        Long id = Thread.currentThread().getId();
        String name = Thread.currentThread().getName();
        Long startTime = System.currentTimeMillis();
        log.debug("线程id:{},线程名称:{},开始时间:{}",id,name,startTime);
        log.debug("计算价格入参:{}",cost);
        ProgressCostVO vo = costService.calculateCost(cost);
        log.debug("计算价格入参:{},出参:{}",cost,vo);
        JsonResult ok = JsonResult.ok(vo);
        log.debug("线程id:{},线程名称:{},耗时:{}",id,name,System.currentTimeMillis() - startTime);
        return ok;
    }
}
